﻿using System;
using System.Threading;
using PandoraBoxApi;

namespace PandoraTest
{
    internal class ConsoleMain
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("class PandoraTest method Main");
//            string ipStr = "127.0.0.1";
            string ipStr = "192.168.10.112";
            int domain = 1;

//            Console.WriteLine("udp connect...");
//            Auto.Initialize(ipStr, domain);
            Console.WriteLine("tcp connect ...");
            bool connected = Auto.InitializeTCP(ipStr, domain, false);
            Console.WriteLine("[connected]:" + connected);

            // try get site number

            int index = 0 ;
            TreeItemType treeItemType = new TreeItemType();
            Auto.GetTreeItemInfo(index, ref treeItemType);
                    
            Console.WriteLine("[index]:0[treeItemType.idPath]:" + treeItemType.idPath);
            Console.WriteLine("[index]:0[treeItemType.projectPath]:" + treeItemType.projectPath);
            Console.WriteLine("[index]:0[treeItemType.type]:" + treeItemType.type);

            Console.WriteLine();
            Console.WriteLine("SetParam:");
            // Set the opacity of layer 3 of site 2 to 240.
            // The parameter will be marked active and transition smoothing applies
            Console.WriteLine("Set[site]:" + 1 + " [layer]:" + 9 + "[Opacity]:" + 111);
            Auto.SetParamDouble(1, 9, "Opacity", 111);

            
            // Set the x position of layer 1 of site 2 to -2 without setting the value active.
            // Use Transition Smoothing
            Console.WriteLine("Set[site]:" + 1 + " [layer]:" + 9 + "[X Pos]:" + -2 + " " + true + " " + false);
            Auto.SetParamDoubleExtended(1, 9, "X Pos", -2, true, false);

            // Set the x position of layer 1 of site 2 to -2 and set value as active.
            // Do not use Transition Smoothing
            Console.WriteLine("Set[site]:" + 1 + " [layer]:" + 9 + "[X Pos]:" + -3 + " " + false + " "+ true);
            Auto.SetParamDoubleExtended(1, 9, "Y Pos", -3, false, true);

            // Store Active
            Auto.StoreActive(1);

            Auto.SetParam(1, 8, "X Pos", -3);
            // Set the Mix parameter of the "White Key" effect on layer 1 of site 2 to a value of 255
            Console.WriteLine("Set[site]:" + 1 + " [layer]:" + 8 + "[White Key|Mix]:" + 255);
            Auto.SetParamDouble(1, 8, "White Key|Mix", 255);

            // if you change param value, must use this api save
            Auto.StoreActive(1);

            Console.WriteLine();
            Console.WriteLine("GetParam:");
            // Get the Y position of layer 1 of site 2
            Console.WriteLine("[site]:1 [layer]:9");
            double x_pos = Auto.GetParam(1, 9, "Pos X");
            double y_pos = Auto.GetParam(1, 9, "Pos Y");
            Console.WriteLine("[Pos X]:" + x_pos);
            Console.WriteLine("[Pos Y]:" + y_pos);

            // Get the "Left" parameter value of effect "Crop Edges" on layer 3 of site 1
            Console.WriteLine("[site]:1 [layer]:3");
            double crop_edges_left = Auto.GetParam(1, 3, "Crop Edges|Left");
            Console.WriteLine("[Crop Edges|Left]:" + crop_edges_left);

            // Get the transport mode of sequence 2 (Play/Stop/Pause)
            
            int sequence_number = 1;
            Console.WriteLine("[sequence_number]:" + sequence_number);
            TransportMode sequence_status = Auto.GetSequenceTransportMode(sequence_number);
            Console.WriteLine("[sequence.status]:" + sequence_status);

            // Get the current time position of sequence 1 and extract the number of seconds
            TimeType sequence_time = new TimeType();
            Auto.GetSequenceTime(sequence_number, ref sequence_time);
            int sequence_seconds = sequence_time.Seconds;
            Console.WriteLine("[sequence_seconds]:" + sequence_seconds);

            Console.WriteLine("Set Sequence 1 Play ...");
            Auto.SetSequenceTransportMode(sequence_number, "Play");
            Thread.Sleep(10 * 1000);
            Auto.SetSequenceTransportMode(sequence_number, "Pause");
            
            AutoError autoError = Auto.GetLastError();
            Console.WriteLine("Try to get last error : " + autoError.ToString());
            Console.WriteLine("Unconnect...");
//            Auto.UnInitialize();
        }
    }
}